06. Exercise: Create the Layout File

ANDK L2 13 Create Layout File SC

Android Developer Documentation:

Now it’s your turn to complete this code.

Every Activity that is visible on the screen needs a layout, defined in a layout file. Because you did not create the MainActivity with a layout from a template during project creation, you are next going to need to add a layout file.

Like other resources, layout files are stored in the res resources folder.

  1. In the Project > Android window, open the res folder, so you can see what is happening.
  2. Right-click res.
  3. In the pop-up menu, select New > Android resource file.

In the New Resource File window:

  1. Name the file activity_main.xml.
  2. For the Resource type, choose Layout.
  3. If it is not already selected, for the Root element, choose LinearLayout.
  4. Verify that the source set is main.
  5. Verify that the directory name is layout.
  6. If everything looks correct, click OK.

This creates the activity_main.xml file in the res/layouts folder.

Notice that if the layout directory, didn’t already exist, Android Studio created it for you.

If you want to start at this step, you can download this exercise code from: Step.01-Exercise-Create-layout-file.

You will find plenty of //TODO comments to help you complete this exercise, and if you get stuck, go back and watch the video again.

Once you’re done, you can check your solution against the solution we’ve provided here: Step.01-Solution-Create-layout-file, or using this git diff.

Task Description:

It’s your turn to create a layout file for the AboutMe app. Check the steps below as you implement them to complete this exercise.

Task List:

Task Feedback:

Great!! You have created a layout file and next we'll add some views.

Solution: Step.01-Solution-Create-layout-file or diff